package com.qikecn.utils;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
/**
 * 读取配置文件信息
 * @author wangst
 */
public class InitPropLoader {
    Properties initProps;
    
    InputStream in;
    private static InitPropLoader initProp;
    public String thisURL;
   
    private InitPropLoader(){
        initProps = new Properties();
        in = null;
        thisURL = getClass().getResource("/").toString();
        thisURL=thisURL.replaceFirst("file:/", "");
        if(!thisURL.substring(1,2).equals(":")){
        	thisURL="/"+thisURL;
        }
        thisURL+="config.properties";
        try
        {
            in = new FileInputStream(thisURL);
            initProps.load(in);
        }catch(Exception e){
            e.printStackTrace();
            System.out.println(e.getMessage());
        }finally{
            try{
                if(in != null)
                    in.close();
            }catch(Exception e2) {}
        }
    }

    public static InitPropLoader getInstance()
    {
        if(initProp == null)
            initProp = new InitPropLoader();
        return initProp;
    }

    public String getProperty(String name)
    {
        if(initProps != null)
            return initProps.getProperty(name);
        else
            return null;
    }

}
